package self.cloud.domain.aliyun.handler;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.alidns.model.v20150109.*;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import self.cloud.domain.aliyun.config.AliyunSdkConfig;

@Configuration
public class AcsClient {
    private static final Logger logger = LoggerFactory.getLogger(AcsClient.class);

    private static final String regionId = "cn-hangzhou";

    @Autowired
    AliyunSdkConfig aliyunSdkConfig;

    @Bean
    public IAcsClient getAcsDomainClient(){
        logger.info("AcsDomainClient init...");

        String domainRegionId = "cn-hangzhou";
        String accessKeyId = this.aliyunSdkConfig.getAccessKeyId();
        String accessSecret = this.aliyunSdkConfig.getAccessSecret();

        logger.info("[domainRegionId]:{}", domainRegionId);
        logger.info("[accessKeyId]:{}", accessKeyId.replaceAll("[a-zA-Z0-9]", "*"));
        logger.info("[accessSecret]:{}", accessSecret.replaceAll("[a-zA-Z0-9]", "*"));

        IClientProfile clientProfile = DefaultProfile.getProfile(domainRegionId, accessKeyId, accessSecret);

        return new DefaultAcsClient(clientProfile);
    }

    @Bean
    public DescribeDomainsRequest getDomainRequest() {
        DescribeDomainsRequest request = new DescribeDomainsRequest();
        return request;
    }

    @Bean
    public DescribeDomainRecordsRequest getDomainRecordsRequest() {
        DescribeDomainRecordsRequest request = new DescribeDomainRecordsRequest();
        return request;
    }

    @Bean
    public DescribeDomainRecordInfoRequest getDescribeDomainRecordInfoRequest() {
        DescribeDomainRecordInfoRequest request = new DescribeDomainRecordInfoRequest();
        return request;
    }

    @Bean
    public UpdateDomainRecordRequest getUpdateDomainRecordRequest() {
        UpdateDomainRecordRequest request = new UpdateDomainRecordRequest();
        return request;
    }

    @Bean
    public AddDomainRecordRequest getAddDomainRecordRequest() {
        AddDomainRecordRequest request = new AddDomainRecordRequest();
        return request;
    }
}
